<script>
import Vue from "vue";
import { detectionToken } from "./api/api";
export default {
  // 微信原生导航栏重改
  onLaunch: function () {
    uni.getSystemInfo({
      success: function (e) {
        let model = e.safeArea.top;
        uni.setStorageSync("safeArea", model); //底部安全距离
        Vue.prototype.$model = model;
        // #ifndef MP
        uni.Vue.prototype.StatusBar = e.statusBarHeight;
        if (e.platform == "android") {
          Vue.prototype.CustomBar = e.statusBarHeight + 50;
        } else {
          Vue.prototype.CustomBar = e.statusBarHeight + 45;
        }
        // #endif
        // #ifdef MP-WEIXIN
        Vue.prototype.StatusBar = e.statusBarHeight;
        let custom = wx.getMenuButtonBoundingClientRect();
        Vue.prototype.Custom = custom;
        Vue.prototype.CustomBar =
          custom.bottom + custom.top - e.statusBarHeight;
        // #endif
        // #ifdef MP-ALIPAY
        Vue.prototype.StatusBar = e.statusBarHeight;
        Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
        // #endif
        uni.setStorageSync("CustomBar", Vue.prototype.CustomBar);
      },
    });

    //版本更新
    if (uni.canIUse("getUpdateManager")) {
      const updateManager = wx.getUpdateManager();
      updateManager.onCheckForUpdate(function (res) {
        console.log("onCheckForUpdate====", res);
        // 请求完新版本信息的回调
        if (res.hasUpdate) {
          console.log("res.hasUpdate====");
          uni.updateManager.onUpdateReady(function () {
            uni.showModal({
              title: "更新提示",
              content: "新版本已经准备好，是否重启应用？",
              success: function (res) {
                console.log("success====", res);
                // res: {errMsg: "showModal: ok", cancel: false, confirm: true}
                if (res.confirm) {
                  // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
                  uni.updateManager.applyUpdate();
                } else if (res.cancel) {
                  // //用户点击取消按钮的处理，如果需要强制更新，则给出二次弹窗，如果不需要，则这里的代码都可以删掉了
                  // uni.showModal({
                  //   title: "温馨提示~",
                  //   content:
                  //     "本次版本更新涉及到新的功能添加，旧版本无法正常访问的哦~",
                  //   showCancel: false, //隐藏取消按钮
                  //   confirmText: "确定更新", //只保留确定更新按钮
                  //   success: function (res) {
                  //     if (res.confirm) {
                  //       updateManager.applyUpdate();
                  //     }
                  //   },
                  // });
                }
              },
            });
          });
          uni.updateManager.onUpdateFailed(function () {
            // 新的版本下载失败
            uni.showModal({
              title: "已经有新版本了哟~",
              content: "新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~",
            });
          });
        }
      });
    }
  },
  onShow:function() {
    uni.checkSession({
      success: (res) => {
        //有效果
        console.log("执行检查 未过期");
      },
      fail: (err) => {
        //过了时效性
        uni.removeStorageSync("userInfo");
        console.log("执行检查 已过期");
      },
    });
    //检测本地token的时效性
    let token = uni.getStorageSync("userInfo").token || "";
    if (token) {
      detectionToken().then((res) => {
        console.log(data);
        let data = res[1].data.data;
        if (data == [] || data == null || data == undefined) {
          //清空个人信息
          uni.removeStorageSync("userInfo");
        }
      });
    }
    console.log('ONSHOW')
  },
  onHide: function () {
    console.log("App Hide");
  },
};
</script>

<style lang="scss">
@import url("./style/icon");
@import url("./style/main");

/*每个页面公共css */
view,
	text,
	/* navigator, */
	input,
	image,
	/* swiper, */
	swiper-item,
	page {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

page {
  position: absolute;
  font-size: 20rpx;
  font-family: PingFang SC;
  background: rgba(245, 245, 245, 1);
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: auto;
  height: 100%;
  width: 100vw;
}

image {
  width: 100%;
  display: block;
  will-change: transform;
}

.bgcolorfff {
  background-color: #ffffff;
  font-size: 42rpx;
  font-family: PingFang SC;
  font-weight: bold;
  color: rgba(36, 36, 36, 1);
}

.flex-c {
  display: flex;
  justify-content: center;
  align-items: center;
}

::-webkit-scrollbar {
  width: 0;
  height: 0;
  color: transparent;
}

.custbar_top_text {
  width: 100%;
  display: inline-block;
  font-size: 42rpx;
  font-family: PingFang SC;
  font-weight: bold;
  color: rgba(36, 36, 36, 1);
  text-align: center;
}

.showLikeGift {
  position: fixed;
  left: 0;
  top: 25%;
  z-index: 999999999;
}
.toptext {
  width: 100%;
  display: inline-block;
  font-size: 36rpx !important;
  font-weight: bold;
  color: rgba(36, 36, 36, 1);
  text-align: center;
  font-family: "SourceHanSansCN-Heavy";
}
button {
  &::after {
    border: none !important;
    border-radius: 0 !important;
  }
}
</style>
